<template>
  <el-dialog :title="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑档案'" :close-on-click-modal="false" :visible.sync="visible" class="cu-dialog cu-dialog_center" lock-scroll width="500px" append-to-body>
    <el-form ref="elForm" :model="dataForm" size="small" label-width="100px" label-position="right" :disabled="!!isDetail" :rules="rules" v-loading="loading">
      <el-row>
        <el-col :span="24">
          <el-form-item label="档案编号" prop="fileNo">
            <el-input v-model="dataForm.fileNo" placeholder="请输入档案编号" clearable required :style="{ width: '100%' }"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail" :loading="loading">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import request from '@/utils/request'
import OrgSelect from '@/components/Process/OrgSelect'
export default {
  components: { OrgSelect },
  props: [],
  data() {
    return {
      loading: false,
      visible: false,
      isDetail: false,
      dataForm: {
        id: undefined,
        fileNo: undefined
      },
      rules: {
        fileNo: [
          {
            required: true,
            message: '请输入档案编号',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    init(id) {
      this.dataForm.id = id || ''
      this.visible = true
      this.loading = true
      this.$nextTick(() => {
        this.$refs['elForm'].resetFields()
        request({
          url: `api/campus/contract/${this.dataForm.id}`,
          method: 'get'
        }).then(res => {
          this.dataForm = res.data
        })
        this.loading = false
      })
    },
    dataFormSubmit() {
      this.$refs['elForm'].validate(valid => {
        if (valid) {
          this.loading = true
          if (this.dataForm.id) {
            request({
              url: `/api/finance/contract/${this.dataForm.id}`,
              method: 'put',
              data: { id: this.dataForm.id, fileNo: this.dataForm.fileNo }
            }).then(res => {
              this.loading = false
              this.$message({
                message: res.msg,
                type: 'success',
                duration: 1000,
                onClose: () => {
                  this.visible = false
                  this.$emit('refresh', true)
                }
              })
            })
          }
        }
      })
    }
  }
}
</script>
